package com.jinzhuo;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class pubSubConsumer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("jinzhuo");
        factory.setPassword("jinzhuo");
        factory.setVirtualHost("/jinzhuo");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        DefaultConsumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
//                super.handleDelivery(consumerTag, envelope, properties, body);
                System.out.println(new String(body));
                System.out.println("订阅消费者1已接受消息---");
            }
        };
        channel.basicConsume("pubSubQueue1",true,consumer);

    }
}
